@extends('shop::layouts.master')
@section('title')
    修改管理员
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" lay-filter="form_edit">
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>用户名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="username" name="username" required="" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>将会成为您的登录账户
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="phone" class="layui-form-label">
                        <span class="x-red">*</span>手机
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="phone" name="phone" required="" maxlength="11" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>手机也可作为登录账号
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_nickname" class="layui-form-label">
                        <span class="x-red"></span>昵称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_nickname" name="nickname" required="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_realname" class="layui-form-label">
                        <span class="x-red"></span>真实姓名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_realname" name="realname" required="" autocomplete="off" class="layui-input">
                    </div>
                </div>

                @if($arr_user['is_master'] === 1)
                    <div class="layui-form-item">
                        <label for="L_pass" class="layui-form-label">
                            <span class="x-red">*</span>密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="L_pass" name="pass" required="" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>密码必须同时包含数字和字母的6-18位字符！
                        </div>
                    </div>
                @endif

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>性别</label>
                    <div class="layui-input-inline">
                        <select name="sex">
                            @foreach($arr_sex as $key=>$value)
                                <option value="{{$key}}">{{$value}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                    <div class="layui-input-inline">
                        <select name="role_id">
                            @foreach($arr_role as $key=>$value)
                                <option value="{{$value['id']}}">{{$value['name']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="edit" lay-submit="">修改</button>
                    <input type="hidden" id="L_id" name="id">
                </div>
            </form>
        </div>
    </div>
@endsection

@section('tab_js')
    <script>
        layui.use(['form', 'layer','jquery'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;


                form.render('select');//重新渲染下拉框

                //监听提交
                form.on('submit(edit)',
                    function(data) {
                        var $_url = '{{route('shop_user_update')}}';
                        var $_data = data.field;

                        $.ajax({
                            url:$_url,
                            type:'post',
                            data:$_data,
                            dataType : "json",
                            success:function(result){
                                if(result.state === 0){
                                    layer.msg(
                                        result.msg,
                                        {icon: 6},
                                        function() {
                                            //关闭当前frame
                                            xadmin.close();

                                            // 可以对父窗口进行刷新
                                            xadmin.father_reload();
                                        });
                                }else{
                                    layer.msg(result.msg, {time:2000,icon: 5});
                                }

                            }});
                        return false;

                    });

                //表单初始赋值
                form.val('form_edit', {
                    "id": '{{$arr_data['id']}}',
                    "username": '{{$arr_data['username']}}',
                    "phone": '{{$arr_data['phone']}}',
                    "pass": '{{$arr_data['pass']}}',
                    "realname": '{{$arr_data['realname']}}',
                    "nickname": '{{$arr_data['nickname']}}',
                    "sex": '{{$arr_data['sex']}}',
                    "birthday": '{{$arr_data['birthday']}}',
                    "state": '{{$arr_data['state']}}',
                    "role_id": '{{$arr_data['user_role']['role_id']}}',
                })

            });
    </script>
@endsection




